/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bookshop.facade;

import com.bookshop.entity.Customer;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Thibault
 */
@Stateless
public class CustomerFacade extends AbstractFacade<Customer> {
    @PersistenceContext(unitName = "BookShop-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public CustomerFacade() {
        super(Customer.class);
    }
    public Customer getCustomerAuthentifie(String login, String password){
        Customer customer = null;
        try {
            Query query = em.createNamedQuery("Customer.findByAuthentification");
            query.setParameter("login", login);
            query.setParameter("password", password);
            customer = (Customer) query.getSingleResult();
        } catch (IllegalArgumentException ex) {
            ex.getMessage();
        }
        return customer;
    }
}
